package pers.brozen.anka.support.wechat;


import pers.brozen.anka.support.wechat.request.WeChatRequest;
import pers.brozen.anka.support.wechat.response.WeChatResponse;
import pers.brozen.anka.utils.json.JacksonUtils;

/**
 * @author Brozen
 * @date 2019/10/23 11:31 AM
 */
public class JsonDataConverter<REQ extends WeChatRequest<RES>, RES extends WeChatResponse> implements DataConverter<REQ, RES> {

    private Class<RES> responseClass;

    public JsonDataConverter(Class<RES> responseClass) {
        this.responseClass = responseClass;
    }

    @Override
    public String serialize(REQ request) {
        return JacksonUtils.toJSONString(request);
    }

    @Override
    public RES deserialize(String data) {
        return JacksonUtils.parseObject(data, responseClass);
    }

}
